unit rwFile;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, StdCtrls, Controls, Forms,
  Dialogs, mException;

type
  TArrayValues = array of Double;
  TStrArr = array of String;
  TrwFile = Class(TObject)
 public
     procedure LoadFromTextFile(path: String; var data: TArrayValues);
     procedure SaveToTextFile(path: String; data: TArrayValues);
     function LoadFromConfig(path: String):TStrArr;
     procedure SaveToConfig(path: String; data: TStrArr);
  end;
implementation

procedure TrwFile.LoadFromTextFile(path: String; var data: TArrayValues);
var
  fileContent  : TStringList;
  i : Integer;
begin
  fileContent := TStringList.Create;
  fileContent.LoadFromFile(path);
  SetLength(data, fileContent.Count);
  for i := 0 to fileContent.Count-1 do
    data[i] := StrToFloat(fileContent[i]);

end;

procedure TrwFile.SaveToTextFile(path: String; data: TArrayValues);
var
  fileContent  : TStringList;
  i : Integer;
begin
  fileContent := TStringList.Create;
  for i := 0 to Length(data) - 1 do
    fileContent.Add(FloatToStr(data[i]));
  fileContent.SaveToFile(path);
  fileContent.Free;
end;


function TrwFile.LoadFromConfig(path: String): TStrArr;
var
  fileContent  : TStringList;
  i : Integer;
  temp: TStrArr;
begin
  fileContent := TStringList.Create;
  fileContent.LoadFromFile(path);
  SetLength(temp, fileContent.Count);
  for i := 0 to fileContent.Count-1 do
    temp[i] := fileContent[i];
  Result := temp;
end;

procedure TrwFile.SaveToConfig(path: String; data: TStrArr);
var
  fileContent  : TStringList;
  i : Integer;
begin
  fileContent := TStringList.Create;
  for i := 0 to Length(data) - 1 do
    fileContent.Add(data[i]);
  fileContent.SaveToFile(path);
  fileContent.Free;
end;

end.
